package org.flown.novel;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class MyMetaObjectHandler implements MetaObjectHandler
{

    @Override
    public void insertFill(MetaObject metaObject)
    {
        if (metaObject.hasSetter("registerTime"))
            this.setFieldValByName("registerTime", new Date(System.currentTimeMillis()), metaObject);
        if (metaObject.hasSetter("createTime"))
            this.setFieldValByName("createTime", new Date(System.currentTimeMillis()), metaObject);
        if (metaObject.hasSetter("publishTime"))
            this.setFieldValByName("publishTime", new Date(System.currentTimeMillis()), metaObject);
        if (metaObject.hasSetter("uploadTime"))
            this.setFieldValByName("uploadTime", new Date(System.currentTimeMillis()), metaObject);
        if (metaObject.hasSetter("updateTime"))
            this.setFieldValByName("updateTime", new Date(System.currentTimeMillis()), metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject)
    {
        if (metaObject.hasSetter("updateTime"))
            this.setFieldValByName("updateTime", new Date(System.currentTimeMillis()), metaObject);
    }
}
